package com.aqoods

import static org.junit.Assert.*
import org.junit.*

import com.aqadoos.Post
import com.aqadoos.User

class PostIntegrationTests {

    @Before
    void setUp() {
        // Setup logic here
    }

    @After
    void tearDown() {
        // Tear down logic here
    }

    @Test
    void testFirstPost() {
        def user = new User(userId: "aqadoos", password: "abc123").save()
		def post1 = new Post(content: "post1 content")
		user.addToPosts(post1)
		def post2 = new Post(content: "post2 content")
		user.addToPosts(post2)
		def post3 = new Post(content: "post3 content")
		user.addToPosts(post3)
		
		assertEquals 3, User.get(user.id).posts.size()
		
    }
	
	@Test
	void testGetPosts() {
		def user = new User(userId: "aqadoos", password: "abc123").save()
		def post1 = new Post(content: "post1")
		user.addToPosts(post1)
		def post2 = new Post(content: "post2")
		user.addToPosts(post2)
		def post3 = new Post(content: "post3")
		user.addToPosts(post3)
		
		assertEquals 3, User.get(user.id).posts.size()
		
		def foundUser = User.get(user.id)
		def postContents = foundUser.posts.collect{ it.content }
		
		assertEquals (["post1", "post2", "post3"], postContents.sort())
		
	}
}
